<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">

    <h:body>
        <ui:composition template="/resources/template/template.xhtml">
            <ui:define name="content">
                <h:form><p:panel>
                        <f:facet name="header">
                            <h:outputLabel value="INWARD CREDIT DUE"/>

                            <h:panelGrid columns="2">
                                <h:outputLabel value="From Date"/>
                                <p:calendar id="fromDate" value="#{creditCompanyDueController.fromDate}" navigator="true" pattern="dd MMMM yyyy hh mm ss a" >
                                    <f:ajax event="dateSelect" execute="toDate @this"  render="lst"/>
                                </p:calendar>
                                <h:outputLabel value="To Date"/>
                                <p:calendar id="toDate" value="#{creditCompanyDueController.toDate}" navigator="true" pattern="dd MMMM yyyy hh mm ss a" >
                                    <f:ajax event="dateSelect" execute="@this fromDate"  render="lst"/>
                                </p:calendar>
                                <h:outputLabel value="With Out Due Update"/>
                                <p:selectBooleanCheckbox value="#{creditCompanyDueController.withOutDueUpdate}" />
                                <p:spacer width="100" height="1"/>                                
                            </h:panelGrid>
                            <p:commandButton ajax="false" value="Process DUE" action="#{creditCompanyDueController.createInwardCreditDue()}" onclick="onSubmitButton();"/>
                            <p:commandButton ajax="false" value="Print" styleClass="noPrintButton" >
                                <p:printer target="lst"  />
                            </p:commandButton>

                            <p:commandButton actionListener="#{creditCompanyDueController.createInwardCreditDue()}" ajax="false" value="Excel" styleClass="noPrintButton" >
                                <pe:exporter type="xlsx" target="lst" fileName="Due Search(Credit Company)" subTable="true" />
                            </p:commandButton> 
                        </f:facet>
                        <p:dataTable id="lst" value="#{creditCompanyDueController.institutionEncounters}" var="i">
                            <f:facet name="header">
                                <h:outputLabel value="Due Search(Credit Company)"/>
                                <h:outputLabel value=" From : " style="white-space: pre-line"/>
                                <h:outputLabel value="#{creditCompanyDueController.fromDate}">
                                    <f:convertDateTime pattern="dd MMMM yyyy hh:mm:ss a"/>
                                </h:outputLabel>
                                <h:outputLabel value="&emsp;&emsp;To :"/>
                                <h:outputLabel value="#{creditCompanyDueController.toDate}">
                                    <f:convertDateTime pattern="dd MMMM yyyy hh:mm:ss a"/>
                                </h:outputLabel>
                            </f:facet>
                            <p:columnGroup type="header">
                                <p:row>
                                    <p:column headerText="BHT No">                                    
                                    </p:column>
                                    <p:column headerText="Date Of Discharge">                                    
                                    </p:column>
                                    <p:column headerText="Patient Name">                                    
                                    </p:column>
                                    <p:column headerText="Billed Amount">                                    
                                    </p:column>
                                    <p:column headerText="Paid By Patient">                                    
                                    </p:column>
                                    <p:column headerText="Paid By Company">                                    
                                    </p:column>
                                    <p:column headerText="Net Amount">                                    
                                    </p:column>
                                </p:row>
                            </p:columnGroup>
                            <p:subTable value="#{i.patientEncounters}" var="b">
                                <f:facet name="header">
                                    <h:outputLabel  value="#{i.institution.name}"/>
                                </f:facet>
                                <p:column>                              
                                    <h:outputLabel value="#{b.bhtNo}" />                                
                                </p:column>
                                <p:column>                              
                                    <h:outputLabel value="#{b.dateOfDischarge}" >
                                        <f:convertDateTime pattern="YYYY MM dd hh:mm:ss a" />
                                    </h:outputLabel>                                
                                </p:column>
                                <p:column>                               
                                    <h:outputLabel value="#{b.patient.person.nameWithTitle}" />                                 
                                </p:column>
                                <p:column style="text-align: right;">                                
                                    <h:outputLabel value="#{b.finalBill.netTotal}" >
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>                                 
                                </p:column>
                                <p:column style="text-align: right;" rendered="#{!creditCompanyDueController.withOutDueUpdate}" >                              
                                    <h:outputLabel value="#{b.finalBill.paidAmount}" >
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </p:column>
                                <p:column style="text-align: right;" rendered="#{creditCompanyDueController.withOutDueUpdate}" >                              
                                    <h:outputLabel value="#{b.transPaidByPatient}" >
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </p:column>
                                <p:column style="text-align: right;" rendered="#{!creditCompanyDueController.withOutDueUpdate}" >                              
                                    <h:outputLabel value="#{b.creditPaidAmount}" >
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </p:column>
                                <p:column style="text-align: right;" rendered="#{creditCompanyDueController.withOutDueUpdate}" >                              
                                    <h:outputLabel value="#{b.transPaidByCompany}" >
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </p:column>
                                <p:column style="text-align: right;" rendered="#{!creditCompanyDueController.withOutDueUpdate}" >                              
                                    <h:outputLabel value="#{b.finalBill.netTotal-(b.finalBill.paidAmount+b.paidByCreditCompany)}" >
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </p:column>
                                <p:column style="text-align: right;" rendered="#{creditCompanyDueController.withOutDueUpdate}" >                              
                                    <h:outputLabel value="#{b.finalBill.netTotal-(b.transPaidByPatient+b.transPaidByCompany)}" >
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </p:column>
                                <p:columnGroup type="footer">
                                    <p:row>
                                        <p:column footerText="Total" colspan="3" />
                                        <p:column style="text-align: right;">
                                            <f:facet name="footer">
                                                <h:outputLabel value="#{i.total}">
                                                    <f:convertNumber pattern="#,##0.00" />
                                                </h:outputLabel>
                                            </f:facet>
                                        </p:column>
                                        <p:column style="text-align: right;" rendered="#{!creditCompanyDueController.withOutDueUpdate}" >
                                            <f:facet name="footer">
                                                <h:outputLabel value="#{i.paidTotalPatient}">
                                                    <f:convertNumber pattern="#,##0.00" />
                                                </h:outputLabel>
                                            </f:facet>
                                        </p:column>
                                        <p:column style="text-align: right;" rendered="#{creditCompanyDueController.withOutDueUpdate}" >
                                            <f:facet name="footer">
                                                <h:outputLabel value="#{i.transPaidTotalPatient}">
                                                    <f:convertNumber pattern="#,##0.00" />
                                                </h:outputLabel>
                                            </f:facet>
                                        </p:column>
                                        <p:column style="text-align: right;" rendered="#{!creditCompanyDueController.withOutDueUpdate}" >
                                            <f:facet name="footer">
                                                <h:outputLabel value="#{i.paidTotal}">
                                                    <f:convertNumber pattern="#,##0.00" />
                                                </h:outputLabel>
                                            </f:facet>
                                        </p:column>
                                        <p:column style="text-align: right;" rendered="#{creditCompanyDueController.withOutDueUpdate}" >
                                            <f:facet name="footer">
                                                <h:outputLabel value="#{i.transPaidTotal}">
                                                    <f:convertNumber pattern="#,##0.00" />
                                                </h:outputLabel>
                                            </f:facet>
                                        </p:column>
                                        <p:column style="text-align: right;" rendered="#{!creditCompanyDueController.withOutDueUpdate}" >
                                            <f:facet name="footer">
                                                <h:outputLabel value="#{i.total-(i.paidTotal+i.paidTotalPatient)}">
                                                    <f:convertNumber pattern="#,##0.00" />
                                                </h:outputLabel>
                                            </f:facet>
                                        </p:column>
                                        <p:column style="text-align: right;" rendered="#{creditCompanyDueController.withOutDueUpdate}" >
                                            <f:facet name="footer">
                                                <h:outputLabel value="#{i.total-(i.transPaidTotalPatient+i.transPaidTotal)}">
                                                    <f:convertNumber pattern="#,##0.00" />
                                                </h:outputLabel>
                                            </f:facet>
                                        </p:column>
                                    </p:row>
                                </p:columnGroup>
                            </p:subTable>
                            <p:columnGroup type="footer">
                                <p:row>
                                    <p:column footerText="Total" colspan="3" />
                                    <p:column style="text-align: right;">
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{creditCompanyDueController.finalTotal}">
                                                <f:convertNumber pattern="#,##0.00" />
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>
                                    <p:column style="text-align: right;" rendered="#{!creditCompanyDueController.withOutDueUpdate}" >
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{creditCompanyDueController.finalPaidTotalPatient}">
                                                <f:convertNumber pattern="#,##0.00" />
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>
                                    <p:column style="text-align: right;" rendered="#{creditCompanyDueController.withOutDueUpdate}" >
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{creditCompanyDueController.finalTransPaidTotalPatient}">
                                                <f:convertNumber pattern="#,##0.00" />
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>
                                    <p:column style="text-align: right;" rendered="#{!creditCompanyDueController.withOutDueUpdate}" >
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{creditCompanyDueController.finalPaidTotal}">
                                                <f:convertNumber pattern="#,##0.00" />
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>
                                    <p:column style="text-align: right;" rendered="#{creditCompanyDueController.withOutDueUpdate}" >
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{creditCompanyDueController.finalTransPaidTotal}">
                                                <f:convertNumber pattern="#,##0.00" />
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>
                                    <p:column style="text-align: right;" rendered="#{!creditCompanyDueController.withOutDueUpdate}" >
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{creditCompanyDueController.finalTotal-(creditCompanyDueController.finalPaidTotal+creditCompanyDueController.finalPaidTotalPatient)}">
                                                <f:convertNumber pattern="#,##0.00" />
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>
                                    <p:column style="text-align: right;" rendered="#{creditCompanyDueController.withOutDueUpdate}" >
                                        <f:facet name="footer">
                                            <h:outputLabel value="#{creditCompanyDueController.finalTotal-(creditCompanyDueController.finalTransPaidTotalPatient+creditCompanyDueController.finalTransPaidTotal)}">
                                                <f:convertNumber pattern="#,##0.00" />
                                            </h:outputLabel>
                                        </f:facet>
                                    </p:column>
                                </p:row>
                            </p:columnGroup>

                        </p:dataTable>
                        <f:facet name="footer" >
                            <h:outputLabel value="Printed By : #{sessionController.loggedUser.webUserPerson.name}" style="float: right"/>
                        </f:facet>
                    </p:panel>
                </h:form>
            </ui:define>


        </ui:composition>

    </h:body>
</html>
